﻿using System.Windows.Data;
using System.Windows.Markup;

namespace ThunderboltHelper.Language;

[MarkupExtensionReturnType(typeof(BindingExpression))]
public class StringResourceExtension: MarkupExtension
{
	/// <summary>
	/// 资源的名称，与资源文件StringResource.resx对应
	/// </summary>
	[ConstructorArgument("key")]
	public string Key
	{
		get;
		set;
	}

	/// <summary>
	/// 获取资源内容
	/// </summary>
	public string Value { get => StringResourceManager.GetString(this.GetType(), Key); }

	public StringResourceExtension(string key)
		: this()
	{
		Key = key;
	}

	public StringResourceExtension()
	{
	}
	/// <summary>
	/// 重写函数
	/// </summary>
	/// <param name="serviceProvider"></param>
	/// <returns></returns>
	public override object ProvideValue(IServiceProvider serviceProvider)
	{
		Binding binding = new Binding("Value") { Source = this, Mode = BindingMode.OneWay };
		return binding.ProvideValue(serviceProvider);
	}

}